package lc.二叉树.剑指Offer;

import utils.TreeNode;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @description:
 * @author: qian
 * @createDate: 2021/10/11
 */
public class 剑指OfferII045_二叉树最底层最左边的值 {

    public int findBottomLeftValue(TreeNode root) {


        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(root);
        int left = 0;
        while (!queue.isEmpty()) {

            int size = queue.size();
            left = queue.peek().val;
            for (int i = 0; i < size; i++) {
                TreeNode node = queue.poll();
                if (node.left != null) queue.add(node.left);
                if (node.right != null) queue.add(node.right);
            }

        }
        return left;
    }
}
